package com.wushijia.test;

import lombok.Getter;

public class FatherChild {

  public static void main(String[] args) {
    Father child = new Child();
    //对于一个引用类型的变量而言，当通过该变量访问它所引用的对象的实例变量时，该实例变量的值取决于声明该变量时类型
    System.out.println(child.getName());
    child.print();

    System.out.println("==============================");

    Father father = new Father();
    father.print();
    System.out.println(father.getName());
  }
}

@Getter
class Father {

  private String name = "father";

  static {
    System.out.println("static:father");
  }

  public Father() {
    System.out.println("I'm Father");
  }

  protected void print() {
    System.out.println("father:print()");
  }
}

@Getter
class Child extends Father {

  private String name = "child";

  static {
    System.out.println("static:child");
  }

  public Child() {
    System.out.println("I'm Child");
  }

  public static void main(String[] args) {
    System.out.println("test");
  }

//  @Override
//  protected void print() {
//    System.out.println("child:print()");
//  }
}

@Getter
class Child2 extends Father {

  private String name = "child2";

  static {
    System.out.println("static:child2");
  }

  public Child2() {
    System.out.println("I'm Child2");
  }

  @Override
  protected void print() {
    System.out.println("child2:print()");
  }
}
